package com.example.leetcode.prcatice;

/**
 * 给定一个Excel表格中的列名称，返回其相应的列序号。
 *
 * <p>例如，
 */
public class Test171 {

    public int titleToNumber(String columnTitle) {
        int length = columnTitle.length();
        int len = length;
        int sum = 0;
        for (int i = 0;i<length;i++){
            char c = columnTitle.charAt(i);
            int index = findIndex(c);
            double pow = Math.pow(26, len-1);
            len--;
            sum = (int) (sum + index * pow);
        }
        return sum;
    }


    int findIndex(char c){
        return c - 64;
    }


}


class Demo171{
  public static void main(String[] args) {
    Test171 t = new Test171();
    String columnTitle = "ZY";
    System.out.println(t.titleToNumber(columnTitle));
  }
}